﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NJL.Web.Controls
{
    public partial class WUCVisitorSpaceLeftLastVisitor : BaseUserControl
    {
        private readonly NJL.BLL.NJL_REG_PERSON_VISIT bllPersonVisit = new BLL.NJL_REG_PERSON_VISIT();
        NJL.Model.NJL_REG_PERSON_VISIT modePersonVisit = new Model.NJL_REG_PERSON_VISIT();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (UserId != "" && UserId != Request.QueryString["uid"].ToString() && UserType == "2" || UserType == "3")
                {
                    DataSet isUserid = bllPersonVisit.GetList(1, "CREATE_USER_ID='" + UserId + "' and NJL_PERSON_ID='" + Request.QueryString["uid"] + "'", "CREATE_DATE_TIME desc");
                    if (isUserid.Tables[0].Rows.Count > 0)
                    {
                        modePersonVisit = bllPersonVisit.GetModel(isUserid.Tables[0].Rows[0][0].ToString());
                        modePersonVisit.CREATE_DATE_TIME = DateTime.Now;
                        if (bllPersonVisit.Update(modePersonVisit))
                        {

                        }
                    }
                    else
                    {
                        modePersonVisit.ID = DateTime.Now.ToString("yyyyMMddHHmmssfff") + new Random().Next(100, 999).ToString();
                        modePersonVisit.NJL_PERSON_ID = Request.QueryString["uid"];
                        modePersonVisit.CREATE_USER_ID = UserId;
                        modePersonVisit.CREATE_USER_NAME = UserName;
                        modePersonVisit.CREATE_DATE_TIME = DateTime.Now;
                        modePersonVisit.IP = Request.UserHostAddress;
                        bllPersonVisit.Add(modePersonVisit);
                    }
                }
                DataSet ds = bllPersonVisit.GetList(6, "a.NJL_PERSON_ID='" + Request.QueryString["uid"] + "'", "a.CREATE_DATE_TIME desc");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    rptLogUser.DataSource = ds;
                    rptLogUser.DataBind();
                }
               
            }
        }
    }
}